package com.banshuibao.bsb_android.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.banshuibao.bsb_android.Constants;
import com.banshuibao.bsb_android.R;
import com.banshuibao.bsb_android.http.HttpResponse;
import com.banshuibao.bsb_android.http.HttpUtil;
import com.banshuibao.bsb_android.model.ReportModel;
import com.banshuibao.bsb_android.util.MyEditText;
import com.banshuibao.bsb_android.util.XToast;

public class ReportActivity extends BaseActivity implements View.OnClickListener {
    private TextView commit;
    private TextView question_content;
    private RelativeLayout cause1, cause2, cause3, cause4, cause5, cause6;
    private TextView cause1_tv, cause2_tv, cause3_tv, cause4_tv, cause5_tv, cause6_tv;
    private ImageView check1, check2, check3, check4, check5, check6;
    private MyEditText editText;
    private String cause;//原因
    private String uuid;//问题uuid
    private String title;//问题名字
    private String tease;//吐槽

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_report);
        uuid = getIntent().getStringExtra("uuid");
        title = getIntent().getStringExtra("title");
        initView();
    }

    public void initView() {
        setTitleText("举报");
        commit = findViewById(R.id.menu);
        commit.setVisibility(View.VISIBLE);
        commit.setText("提交");
        question_content = findViewById(R.id.question);
        question_content.setText(title);
        cause1 = findViewById(R.id.cause1);
        cause2 = findViewById(R.id.cause2);
        cause3 = findViewById(R.id.cause3);
        cause4 = findViewById(R.id.cause4);
        cause5 = findViewById(R.id.cause5);
        cause6 = findViewById(R.id.cause6);
        cause1_tv = findViewById(R.id.cause1_tv);
        cause2_tv = findViewById(R.id.cause2_tv);
        cause3_tv = findViewById(R.id.cause3_tv);
        cause4_tv = findViewById(R.id.cause4_tv);
        cause5_tv = findViewById(R.id.cause5_tv);
        cause6_tv = findViewById(R.id.cause6_tv);
        check1 = findViewById(R.id.check_1);
        check2 = findViewById(R.id.check_2);
        check3 = findViewById(R.id.check_3);
        check4 = findViewById(R.id.check_4);
        check5 = findViewById(R.id.check_5);
        check6 = findViewById(R.id.check_6);
        editText = findViewById(R.id.myEdit);
        editText.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                editText.setFocusable(true);
                editText.setFocusableInTouchMode(true);
                editText.requestFocus();
                editText.findFocus();
                return false;
            }
        });
        cause1.setOnClickListener(this);
        cause2.setOnClickListener(this);
        cause3.setOnClickListener(this);
        cause4.setOnClickListener(this);
        cause5.setOnClickListener(this);
        cause6.setOnClickListener(this);
        commit.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.cause1:
                setLayout(R.id.cause1);
                break;
            case R.id.cause2:
                setLayout(R.id.cause2);
                break;
            case R.id.cause3:
                setLayout(R.id.cause3);
                break;
            case R.id.cause4:
                setLayout(R.id.cause4);
                break;
            case R.id.cause5:
                setLayout(R.id.cause5);
                break;
            case R.id.cause6:
                setLayout(R.id.cause6);
                break;
            case R.id.menu:
                tease = editText.getText().toString().trim();
                if (!TextUtils.isEmpty(cause)) {
                    getData(cause, tease);
                } else {
                    XToast.showToast(this, "请选择举报原因");
                    return;
                }
                break;
        }
    }

    public void getData(String cause, String content) {
        ReportModel.body body = new ReportModel.body();
        body.setType("0");
        if (!TextUtils.isEmpty(uuid)) {
            body.setUuid(uuid);
        }
        if (!TextUtils.isEmpty(content)) {
            body.setContent(cause + content);
        } else {
            body.setContent(cause);
        }
        showProgressDialog();
        HttpUtil.doPost(Constants.Url.EXPERT_ANSWER_REPORT, body, new HttpResponse(this) {
            @Override
            public void onResult(Object obj) {
//                String s = (String) obj;
//                LogUtil.e(s);
                XToast.showToast(ReportActivity.this,"举报成功");
                finish();
            }

            @Override
            public void responseEnd() {
                super.responseEnd();
                cancelProgressDialog();
            }
        });
    }

    public void defultState() {
        cause1_tv.setTextColor(getResources().getColor(R.color.text_office_color));
        cause2_tv.setTextColor(getResources().getColor(R.color.text_office_color));
        cause3_tv.setTextColor(getResources().getColor(R.color.text_office_color));
        cause4_tv.setTextColor(getResources().getColor(R.color.text_office_color));
        cause5_tv.setTextColor(getResources().getColor(R.color.text_office_color));
        cause6_tv.setTextColor(getResources().getColor(R.color.text_office_color));
        check1.setVisibility(View.GONE);
        check2.setVisibility(View.GONE);
        check3.setVisibility(View.GONE);
        check4.setVisibility(View.GONE);
        check5.setVisibility(View.GONE);
        check6.setVisibility(View.GONE);
    }

    public void setLayout(int id) {
        defultState();
        switch (id) {
            case R.id.cause1:
                cause = "内容不实";
                cause1_tv.setTextColor(getResources().getColor(R.color.cause_color));
                check1.setVisibility(View.VISIBLE);
                break;
            case R.id.cause2:
                cause = "明显错误";
                cause2_tv.setTextColor(getResources().getColor(R.color.cause_color));
                check2.setVisibility(View.VISIBLE);
                break;
            case R.id.cause3:
                cause = "内容与题目不符";
                cause3_tv.setTextColor(getResources().getColor(R.color.cause_color));
                check3.setVisibility(View.VISIBLE);
                break;
            case R.id.cause4:
                cause = "引用错误";
                cause4_tv.setTextColor(getResources().getColor(R.color.cause_color));
                check4.setVisibility(View.VISIBLE);
                break;
            case R.id.cause5:
                cause = "内容浅显";
                cause5_tv.setTextColor(getResources().getColor(R.color.cause_color));
                check5.setVisibility(View.VISIBLE);
                break;
            case R.id.cause6:
                cause = "其它";
                cause6_tv.setTextColor(getResources().getColor(R.color.cause_color));
                check6.setVisibility(View.VISIBLE);
                break;
        }
    }
}
